package com.pig4cloud.pigx.user.feign;

import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.user.entity.User;
import com.pig4cloud.pigx.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户feign
 *
 * @since 2022/12/11 16:51
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/feign/user")
public class DuckweedUserFeignImpl {

    private final UserService userService;

    /**
     * 根据用户id查询用户
     *
     * @param userId 用户id
     * @param from   标记请求来自系统内部
     * @return {@link R <User>}
     * @since 2022/12/11 16:50
     */
    @Inner
    @GetMapping("/{userId}")
    public R<User> getById(@PathVariable("userId") Long userId, @RequestHeader(SecurityConstants.FROM) String from) {
        User user = userService.getById(userId);
        return R.ok(user);
    }
}
